<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo ($CONF['mallTitle']); ?>后台管理中心</title>
    <link href="/Public/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Tpl/Admin/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <link href="/Public/plugins/jedate/skin/jedate.css" rel="stylesheet">
    <script src="/Public/js/jquery.min.js"></script>
    <script src="/Public/plugins/bootstrap/js/bootstrap.min.js"></script>
    <!--<script src="/Public/js/common.js"></script>-->
    <script src="/Public/plugins/plugins/plugins.js"></script>
    <script src="/Public/js/ueditor/third-party/highcharts/highcharts.js"></script>
    <!--<script src="http://code.highcharts.com/highcharts.js"></script>-->
    <script src="/Public/plugins/jedate/jedate.min.js"></script>
    <script>
      $(function(){
        //默认日期查询、查看订单概况
        var paramsData = {};
        paramsData.status = 1;
        paramsData.dataType = 0;
        paramsData.inpstart = $('#inpstart').val();
        paramsData.inpend = $('#inpend').val();
        $.post("<?php echo U('Admin/Stats/getOrderChart');?>",paramsData,function(data,textStatus){
          var json = eval("("+data+")");
          viewChart(json,paramsData.status,paramsData.dataType);
          //设置日期查询的session
          for(var p =0;p<3;p++){
            paramsData.dataType = p;
            $.post("<?php echo U('Admin/Stats/getOrderChart');?>",paramsData,function(data,textStatus){});
          }
        })
        //监听面板点击事件
        $('#myTab a').click(function (e) {
           e.preventDefault();
           $(this).tab('show');
           //查询数据
           var dataType = $(this).attr('data');
           //查询方式
           var methodSearch = $('#methodSearch').val();
           dataSearch(methodSearch,dataType);
        });
      })
      //查询数据修改
      function dataSearch(status,dataType){
        var params = {};
        params.status = status;
        params.dataType = dataType;
        $('#methodSearch').val(status);
        $('#dataType').val(dataType);
        if(1 == status){
          params.inpstart = $('#inpstart').val();
          params.inpend = $('#inpend').val();
        }else if(2 == status){
          params.ys1 = $('#ys1').val();
          params.ys2 = $('#ys2').val();
          params.ys3 = $('#ys3').val();
          params.ys4 = $('#ys4').val();
          params.ys5 = $('#ys5').val();
        }
        $.post("<?php echo U('Admin/Stats/getOrderChart');?>",params,function(data,textStatus){
          var json = eval("("+data+")");
          viewChart(json,status,dataType);
        })
      }
      //查询方式修改
      function dataFind(status){
        var dataType = $('#dataType').val();
        var params = {};
        params.status = status;
        params.dataType = dataType;
        $('#methodSearch').val(status);
        $('#dataType').val(dataType);
        if(1 == status){
          params.inpstart = $('#inpstart').val();
          params.inpend = $('#inpend').val();
          $('#export').show();
        }else if(2 == status){
          params.ys1 = $('#ys1').val();
          params.ys2 = $('#ys2').val();
          params.ys3 = $('#ys3').val();
          params.ys4 = $('#ys4').val();
          params.ys5 = $('#ys5').val();
          $('#export').hide();
        }
        $.post("<?php echo U('Admin/Stats/getOrderChart');?>",params,function(data,textStatus){
          var json = eval("("+data+")");
          viewChart(json,status,dataType);
          //设置日期查询的session
          params.status = 1;
          for(var p=0;p<3;p++){
            params.dataType = p;
            $.post("<?php echo U('Admin/Stats/getOrderChart');?>",params,function(data,textStatus){});
          }
        })
      }
      //导出数据
      function ExportSelected(status){
        var params = {};
        params.status = status;
        var jsonText = JSON.stringify(params);
        location.href="/index.php/Admin/Stats/outExcel/data/"+jsonText;
      }
    </script>
  </head>
  <body class='wst-page'>
    <div class='wst-tbar' style='float:left;height:25px;' >
      <font color='red'>*</font>以下统计数据包含已删除会员的订单，订单为从待受理到已到货状态的所有普通、团购、秒杀、积分、拍卖的有效订单
    </div>
    <div class='wst-tbar' style='text-align:right;height:25px;' id="export">
      <?php if(in_array('spfl_01',$WST_STAFF['grant'])){ ?>
      <a class="btn btn-info glyphicon glyphicon-download-alt" href="javascript:ExportSelected(2)" style='float:right'>订单统计报表下载</a>
      <?php } ?>
    </div>
    <div style="clear:both;"></div>
    <div class='wst-tbar'> 
      <span style="font-weight: bold">有效订单总金额：</span>￥<?php echo ($object); ?>
    </div>
    <input type="hidden" id='methodSearch' value="1">
    <input type="hidden" id='dataType' value="0">
    <form method='post' action='' autocomplete="off">
      <div class='wst-tbar'> 
        开始日期：<input class="datainp wicon " id="inpstart" type="text" value="<?php echo $inpstart?$inpstart:''; ?>" readonly='readonly' style='width:100px;' />
        结束日期：<input class="datainp wicon" id="inpend" type="text"   value="<?php echo $inpend?$inpend:''; ?>" readonly='readonly' style='width:100px;' />
        <button type="button" class="btn btn-primary glyphicon glyphicon-search" onclick="dataFind(1)">查询</button> 
      </div>
    </form>
    <form method='post' autocomplete="off">
      <div class='wst-tbar'>            
        查询年月：<input class="datainp wicon " id="ys1" type="text"  value="<?php echo $startDate?$startDate:''; ?>" readonly='readonly' style='width:80px;'/>
        +<input class="datainp wicon " id="ys2" type="text"  value="<?php echo $startDate?$startDate:''; ?>" readonly='readonly' style='width:80px;'/>
        +<input class="datainp wicon " id="ys3" type="text"  value="<?php echo $startDate?$startDate:''; ?>" readonly='readonly' style='width:80px;'/>
        +<input class="datainp wicon " id="ys4" type="text"  value="<?php echo $startDate?$startDate:''; ?>" readonly='readonly' style='width:80px;'/>
        +<input class="datainp wicon " id="ys5" type="text"  value="<?php echo $startDate?$startDate:''; ?>" readonly='readonly' style='width:80px;'/>            
        <button type="button" class="btn btn-primary glyphicon glyphicon-search" onclick="dataFind(2)">查询</button> 
      </div>
    </form>
   <ul id="myTab" class="nav nav-tabs wst-tab" role="tablist">
      <li class="active"><a href="#tabc0" role="tab" data-toggle="tab" data='0'>订单概况</a></li>
      <li><a href="#tabc1" role="tab" data-toggle="tab" data='1'>配送方式</a></li>
      <li><a href="#tabc2" role="tab" data-toggle="tab" data='2'>支付方式</a></li>
   </ul>
   <div class='tab-content wst-tab-content'>
      <div class='tab-pane active in fade wst-tab-pane' id='tabc0'>
         <div id="container0_1" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
         <div id="container0_2" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
      </div>
      <div class='tab-pane active in fade wst-tab-pane' id='tabc1'>
         <div id="container1_1" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
         <div id="container1_2" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
      </div>
      <div class='tab-pane active in fade wst-tab-pane' id='tabc2'>
         <div id="container2_1" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
         <div id="container2_2" style="height: 400px;width:500px; margin: 0 auto;display: none;"></div>
      </div>
   </div>
   <script type="text/javascript">
    function viewChart(data,status,page){
      var title = '';
      if(0 == page){
        title = '订单概况';
        ytitle = '数量';
      }else if(1 == page){
        title = '配送方式';
        ytitle = '数量';
      }else if(2 == page){
        title = '支付方式';
        ytitle = '数量';
      }
      if(status == 1){
        $('#container'+page+'_1').show();
        $('#container'+page+'_2').hide();
        $('#container'+page+'_1').highcharts({
          chart: {
             plotBackgroundColor: null,
             plotBorderWidth: null,
             plotShadow: false,
             type: 'pie'
          },
          title: {
             text: title
          },
          credits: {  
             enabled: false  
          }, 
          tooltip: {
             pointFormat: '{series.name}: <b>{point.y}</b>'
          },
          plotOptions: {
             pie: {
                 allowPointSelect: true,
                 cursor: 'pointer',
                 dataLabels: {
                     enabled: true,
                     format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                     style: {
                         color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                     }
                 }
             }
          },
          series: [{
             name: '数量',
             colorByPoint: true,
             data: data.series
          }]
        });
      }else if(status == 2){
        $('#container'+page+'_2').show();
        $('#container'+page+'_1').hide();
        $('#container'+page+'_2').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: title
            },
            credits: {  
             enabled: false  
            }, 
            xAxis: {
                categories: data.categories,
                crosshair: true
            },
            yAxis: {
                min: 0,
                title: {
                    text: ytitle
                }
            },
            tooltip: {
                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y}</b></td></tr>',
                footerFormat: '</table>',
                shared: true,
                useHTML: true
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: data.series
        });
      }
    }
   </script>
   <script>
    var start = {
        format: 'YYYY-MM-DD ',
        //festival:true,
        //isinitVal:true,
        choosefun: function(elem,datas){
            end.minDate = datas; //开始日选好后，重置结束日的最小日期
        }
    };
    var end = {
        format: 'YYYY-MM-DD ',
        //festival:true,
        //isinitVal:true,
        choosefun: function(elem,datas){
            start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    $("#inpstart").jeDate(start);
    $("#inpend").jeDate(end);
    var ys5 = {
      format: 'YYYY-MM ',
    };
    var ys1 = {
      format: 'YYYY-MM ',
    };
    var ys2 = {
      format: 'YYYY-MM ',
    };
    var ys3 = {
      format: 'YYYY-MM ',
    };
    var ys4 = {
      format: 'YYYY-MM ',
    };
    $("#ys1").jeDate(ys1);
    $("#ys2").jeDate(ys2);
    $("#ys3").jeDate(ys3);
    $("#ys4").jeDate(ys4);
    $("#ys5").jeDate(ys5);
   </script>
</body>
</html>